<!DOCTYPE html>
<html lang="en">
<head>
  <title>Definition Stage - Vert.x</title>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <meta content="Vert.x is a tool-kit for building reactive applications on the JVM." name="description">
  <link href="http://vertx.io/stylesheets/docs.css" media="screen" rel="stylesheet">
  <link href="http://vertx.io/stylesheets/font-awesome.min.css" media="screen" rel="stylesheet">
  <link href="http://vertx.io/javascripts/styles/rainbow.min.css" media="screen" rel="stylesheet">
  <!-- IE 6-8 support of HTML 5 elements -->
  <!--[if lt IE 9]>
  <script src="http://static.jboss.org/theme/js/libs/html5/pre3.6/html5.min.js"></script>
  <![endif]-->

  <link rel="apple-touch-icon" sizes="57x57" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-57x57.png">
  <link rel="apple-touch-icon" sizes="60x60" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-60x60.png">
  <link rel="apple-touch-icon" sizes="72x72" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-72x72.png">
  <link rel="apple-touch-icon" sizes="76x76" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-76x76.png">
  <link rel="apple-touch-icon" sizes="114x114" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-114x114.png">
  <link rel="apple-touch-icon" sizes="120x120" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-120x120.png">
  <link rel="apple-touch-icon" sizes="144x144" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-144x144.png">
  <link rel="apple-touch-icon" sizes="152x152" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-152x152.png">
  <link rel="apple-touch-icon" sizes="180x180" href="http://vertx.io/assets/favicons/vertx-favicon-7/apple-touch-icon-180x180.png">
  <link rel="icon" type="image/png" href="http://vertx.io/assets/favicons/vertx-favicon-7/favicon-32x32.png" sizes="32x32">
  <link rel="icon" type="image/png" href="http://vertx.io/assets/favicons/vertx-favicon-7/android-chrome-192x192.png" sizes="192x192">
  <link rel="icon" type="image/png" href="http://vertx.io/assets/favicons/vertx-favicon-7/favicon-96x96.png" sizes="96x96">
  <link rel="icon" type="image/png" href="http://vertx.io/assets/favicons/vertx-favicon-7/favicon-16x16.png" sizes="16x16">
  <link rel="manifest" href="http://vertx.io/assets/favicons/vertx-favicon-7/manifest.json">
  <link rel="mask-icon" href="http://vertx.io/assets/favicons/vertx-favicon-7/safari-pinned-tab.svg" color="#5bbad5">
  <meta name="msapplication-TileColor" content="#7d3194">
  <meta name="msapplication-TileImage" content="http://vertx.io/assets/favicons/vertx-favicon-7/mstile-144x144.png">
  <meta name="theme-color" content="#ffffff">

  <link href="http://fonts.googleapis.com/css?family=Ubuntu:400,500,700,400italic" rel="stylesheet" type="text/css">
  <link rel="alternate" type="application/rss+xml" title="RSS"
     href="http://vertx.io/feed.xml">
  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    ga('create', 'UA-30144458-1', 'auto');
    ga('create', 'UA-71153120-1', 'auto', 'tracker');
    ga('send', 'pageview');
    ga('tracker.send', 'pageview');
  </script>
</head>
<body>

<a href="http://www.reactivemanifesto.org/" id="reactive-manifesto-banner">
  <img style="border: 0; position: fixed; right: 0; top:0; z-index: 9000"
    src="http://d379ifj7s9wntv.cloudfront.net/reactivemanifesto/images/ribbons/we-are-reactive-black-right.png">
</a>

<a id="skippy" class="sr-only sr-only-focusable" href="#content"><div class="container"><span class="skiplink-text">Skip to main content</span></div></a>

<header class="navbar navbar-default navbar-static-top" id="top" role="banner">
  <div class="container">
    <div class="navbar-header">
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#vertx-navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a href="http://vertx.io/" class="navbar-brand"><img alt="Brand" src="http://vertx.io/assets/logo-sm.png"></a>
    </div>
    <nav class="collapse navbar-collapse" id="vertx-navbar-collapse">
      <ul class="nav navbar-nav navbar-right">
        <li><a href="http://vertx.io/download/">Download</a></li>
        <li><a href="http://vertx.io/docs/">Documentation</a></li>
        <li><a href="https://github.com/vert-x3/wiki/wiki">Wiki</a></li>
        <li><a href="http://vertx.io/community/">Community</a></li>
        <li><a href="http://vertx.io/materials/">Materials</a></li>
        <li><a href="http://vertx.io/blog/">Blog</a></li>        
      </ul>
    </nav>
  </div>
</header>



  <div class="page-header" id="content">
    <div class="container">
      <div class="row">
        <div class="col-sm-12">
          <h1>Definition Stage</h1>
          
        </div>
      </div>
    </div>
  </div>




<div id="content">
  <div class="container docs-content">
    <div class="row">
      <div class="col-sm-12 col-md-push-9 col-md-3 hidden-xs hidden-sm">
        <div id="sidebar" data-spy="affix">
          <ul class="sectlevel2">
<li><a href="#_definition_stage">Definition Stage</a></li>
<li><a href="#_parsing_stage">Parsing Stage</a></li>
<li><a href="#_query_interrogation_stage">Query / Interrogation Stage</a></li>
<li><a href="#_typed_options_and_arguments">Typed options and arguments</a></li>
<li><a href="#_using_annotations">Using annotations</a></li>
</ul>
        </div>
      </div>
      <div class="col-sm-12 col-md-pull-3 col-md-9">
        <div class="toc hidden-md hidden-lg">
          <h2>Table of Contents</h2>
          <ul class="sectlevel2">
<li><a href="#_definition_stage">Definition Stage</a></li>
<li><a href="#_parsing_stage">Parsing Stage</a></li>
<li><a href="#_query_interrogation_stage">Query / Interrogation Stage</a></li>
<li><a href="#_typed_options_and_arguments">Typed options and arguments</a></li>
<li><a href="#_using_annotations">Using annotations</a></li>
</ul>
        </div>
        <div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Vert.x Core provides an API for parsing command line arguments passed to programs.</p>
</div>
<div class="paragraph">
<p>It&#8217;s also able to print help
messages detailing the options available for a command line tool. Even if such features are far from
the Vert.x core topics, this API is used in the <code><a href="../../apidocs/io/vertx/core/Launcher.html">Launcher</a></code> class that you can use in <em>fat-jar</em>
and in the <code>vertx</code> command line tools. In addition, it&#8217;s polyglot (can be used from any supported language) and is
used in Vert.x Shell.</p>
</div>
<div class="paragraph">
<p>Vert.x CLI provides a model to describe your command line interface, but also a parser. This parser supports
different types of syntax:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>POSIX like options (ie. <code>tar -zxvf foo.tar.gz</code>)</p>
</li>
<li>
<p>GNU like long options (ie. <code>du --human-readable --max-depth=1</code>)</p>
</li>
<li>
<p>Java like properties (ie. <code>java -Djava.awt.headless=true -Djava.net.useSystemProxies=true Foo</code>)</p>
</li>
<li>
<p>Short options with value attached (ie. <code>gcc -O2 foo.c</code>)</p>
</li>
<li>
<p>Long options with single hyphen (ie. <code>ant -projecthelp</code>)</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Using the CLI api is a 3-steps process:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>The definition of the command line interface</p>
</li>
<li>
<p>The parsing of the user command line</p>
</li>
<li>
<p>The query / interrogation</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_definition_stage">Definition Stage</h3>
<div class="paragraph">
<p>Each command line interface must define the set of options and arguments that will be used. It also requires a
name. The CLI API uses the <code><a href="../../apidocs/io/vertx/core/cli/Option.html">Option</a></code> and <code><a href="../../apidocs/io/vertx/core/cli/Argument.html">Argument</a></code> classes to
describe options and arguments:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create("copy")
    .setSummary("A command line interface to copy files.")
    .addOption(new Option()
        .setLongName("directory")
        .setShortName("R")
        .setDescription("enables directory support")
        .setFlag(true))
    .addArgument(new Argument()
        .setIndex(0)
        .setDescription("The source")
        .setArgName("source"))
    .addArgument(new Argument()
        .setIndex(0)
        .setDescription("The destination")
        .setArgName("target"));</code></pre>
</div>
</div>
<div class="paragraph">
<p>As you can see, you can create a new <code><a href="../../apidocs/io/vertx/core/cli/CLI.html">CLI</a></code> using
<code><a href="../../apidocs/io/vertx/core/cli/CLI.html#create-java.lang.String-">CLI.create</a></code>. The passed string is the name of the CLI. Once created you
can set the summary and description. The summary is intended to be short (one line), while the description can
contain more details. Each option and argument are also added on the <code>CLI</code> object using the
<code><a href="../../apidocs/io/vertx/core/cli/CLI.html#addArgument-io.vertx.core.cli.Argument-">addArgument</a></code> and
<code><a href="../../apidocs/io/vertx/core/cli/CLI.html#addOption-io.vertx.core.cli.Option-">addOption</a></code> methods.</p>
</div>
<div class="sect3">
<h4 id="_options">Options</h4>
<div class="paragraph">
<p>An <code><a href="../../apidocs/io/vertx/core/cli/Option.html">Option</a></code> is a command line parameter identified by a <em>key</em> present in the user command
line. Options must have at least a long name or a short name. Long name are generally used using a <code>--</code> prefix,
while short names are used with a single <code>-</code>. Options can get a description displayed in the usage (see below).
Options can receive 0, 1 or several values. An option receiving 0 values is a <code>flag</code>, and must be declared using
<code><a href="../../apidocs/io/vertx/core/cli/Option.html#setFlag-boolean-">setFlag</a></code>. By default, options receive a single value, however, you can
configure the option to receive several values using <code><a href="../../apidocs/io/vertx/core/cli/Option.html#setMultiValued-boolean-">setMultiValued</a></code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create("some-name")
    .setSummary("A command line interface illustrating the options valuation.")
    .addOption(new Option()
        .setLongName("flag").setShortName("f").setFlag(true).setDescription("a flag"))
    .addOption(new Option()
        .setLongName("single").setShortName("s").setDescription("a single-valued option"))
    .addOption(new Option()
        .setLongName("multiple").setShortName("m").setMultiValued(true)
        .setDescription("a multi-valued option"));</code></pre>
</div>
</div>
<div class="paragraph">
<p>Options can be marked as mandatory. A mandatory option not set in the user command line throws an exception during
the parsing:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create("some-name")
    .addOption(new Option()
        .setLongName("mandatory")
        .setRequired(true)
        .setDescription("a mandatory option"));</code></pre>
</div>
</div>
<div class="paragraph">
<p>Non-mandatory options can have a <em>default value</em>. This value would be used if the user does not set the option in
the command line:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create("some-name")
    .addOption(new Option()
        .setLongName("optional")
        .setDefaultValue("hello")
        .setDescription("an optional option with a default value"));</code></pre>
</div>
</div>
<div class="paragraph">
<p>An option can be <em>hidden</em> using the <code><a href="../../apidocs/io/vertx/core/cli/Option.html#setHidden-boolean-">setHidden</a></code> method. Hidden option are
not listed in the usage, but can still be used in the user command line (for power-users).</p>
</div>
<div class="paragraph">
<p>If the option value is contrained to a fixed set, you can set the different acceptable choices:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create("some-name")
    .addOption(new Option()
        .setLongName("color")
        .setDefaultValue("green")
        .addChoice("blue").addChoice("red").addChoice("green")
        .setDescription("a color"));</code></pre>
</div>
</div>
<div class="paragraph">
<p>Options can also be instantiated from their JSON form.</p>
</div>
</div>
<div class="sect3">
<h4 id="_arguments">Arguments</h4>
<div class="paragraph">
<p>Unlike options, arguments do not have a <em>key</em> and are identified by their <em>index</em>. For example, in
<code>java com.acme.Foo</code>, <code>com.acme.Foo</code> is an argument.</p>
</div>
<div class="paragraph">
<p>Arguments do not have a name, there are identified using a 0-based index. The first parameter has the
index <code>0</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create("some-name")
    .addArgument(new Argument()
        .setIndex(0)
        .setDescription("the first argument")
        .setArgName("arg1"))
    .addArgument(new Argument()
        .setIndex(1)
        .setDescription("the second argument")
        .setArgName("arg2"));</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you don&#8217;t set the argument indexes, it computes it automatically by using the declaration order.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create("some-name")
    // will have the index 0
    .addArgument(new Argument()
        .setDescription("the first argument")
        .setArgName("arg1"))
    // will have the index 1
    .addArgument(new Argument()
        .setDescription("the second argument")
        .setArgName("arg2"));</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>argName</code> is optional and used in the usage message.</p>
</div>
<div class="paragraph">
<p>As options, <code><a href="../../apidocs/io/vertx/core/cli/Argument.html">Argument</a></code> can:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>be hidden using <code><a href="../../apidocs/io/vertx/core/cli/Argument.html#setHidden-boolean-">setHidden</a></code></p>
</li>
<li>
<p>be mandatory using <code><a href="../../apidocs/io/vertx/core/cli/Argument.html#setRequired-boolean-">setRequired</a></code></p>
</li>
<li>
<p>have a default value using <code><a href="../../apidocs/io/vertx/core/cli/Argument.html#setDefaultValue-java.lang.String-">setDefaultValue</a></code></p>
</li>
<li>
<p>receive several values using <code><a href="../../apidocs/io/vertx/core/cli/Argument.html#setMultiValued-boolean-">setMultiValued</a></code> - only the last argument
can be multi-valued.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Arguments can also be instantiated from their JSON form.</p>
</div>
</div>
<div class="sect3">
<h4 id="_usage_generation">Usage generation</h4>
<div class="paragraph">
<p>Once your <code><a href="../../apidocs/io/vertx/core/cli/CLI.html">CLI</a></code> instance is configured, you can generate the <em>usage</em> message:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create("copy")
    .setSummary("A command line interface to copy files.")
    .addOption(new Option()
        .setLongName("directory")
        .setShortName("R")
        .setDescription("enables directory support")
        .setFlag(true))
    .addArgument(new Argument()
        .setIndex(0)
        .setDescription("The source")
        .setArgName("source"))
    .addArgument(new Argument()
        .setIndex(0)
        .setDescription("The destination")
        .setArgName("target"));

StringBuilder builder = new StringBuilder();
cli.usage(builder);</code></pre>
</div>
</div>
<div class="paragraph">
<p>It generates an usage message like this one:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code>Usage: copy [-R] source target

A command line interface to copy files.

  -R,--directory   enables directory support</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you need to tune the usage message, check the <code><a href="../../apidocs/io/vertx/core/cli/UsageMessageFormatter.html">UsageMessageFormatter</a></code> class.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_parsing_stage">Parsing Stage</h3>
<div class="paragraph">
<p>Once your <code><a href="../../apidocs/io/vertx/core/cli/CLI.html">CLI</a></code> instance is configured, you can parse the user command line to evaluate
each option and argument:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CommandLine commandLine = cli.parse(userCommandLineArguments);</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code><a href="../../apidocs/io/vertx/core/cli/CLI.html#parse-java.util.List-">parse</a></code> method returns a <code><a href="../../apidocs/io/vertx/core/cli/CommandLine.html">CommandLine</a></code>
object containing the values. By default, it validates the user command line and checks that each mandatory options
and arguments have been set as well as the number of values received by each option. You can disable the
validation by passing <code>false</code> as second parameter of <code><a href="../../apidocs/io/vertx/core/cli/CLI.html#parse-java.util.List-boolean-">parse</a></code>.
This is useful if you want to check an argument or option is present even if the parsed command line is invalid.</p>
</div>
<div class="paragraph">
<p>You can check whether or not the
<code><a href="../../apidocs/io/vertx/core/cli/CommandLine.html">CommandLine</a></code> is valid using <code><a href="../../apidocs/io/vertx/core/cli/CommandLine.html#isValid--">isValid</a></code>.</p>
</div>
</div>
<div class="sect2">
<h3 id="_query_interrogation_stage">Query / Interrogation Stage</h3>
<div class="paragraph">
<p>Once parsed, you can retrieve the values of the options and arguments from the
<code><a href="../../apidocs/io/vertx/core/cli/CommandLine.html">CommandLine</a></code> object returned by the <code><a href="../../apidocs/io/vertx/core/cli/CLI.html#parse-java.util.List-">parse</a></code>
method:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CommandLine commandLine = cli.parse(userCommandLineArguments);
String opt = commandLine.getOptionValue("my-option");
boolean flag = commandLine.isFlagEnabled("my-flag");
String arg0 = commandLine.getArgumentValue(0);</code></pre>
</div>
</div>
<div class="paragraph">
<p>One of your option can have been marked as "help". If a user command line enabled a "help" option, the validation
won&#8217;t failed, but give you the opportunity to check if the user asks for help:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create("test")
    .addOption(
        new Option().setLongName("help").setShortName("h").setFlag(true).setHelp(true))
    .addOption(
        new Option().setLongName("mandatory").setRequired(true));

CommandLine line = cli.parse(Collections.singletonList("-h"));

// The parsing does not fail and let you do:
if (!line.isValid() &amp;&amp; line.isAskingForHelp()) {
  StringBuilder builder = new StringBuilder();
  cli.usage(builder);
  stream.print(builder.toString());
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_typed_options_and_arguments">Typed options and arguments</h3>
<div class="paragraph">
<p>The described <code><a href="../../apidocs/io/vertx/core/cli/Option.html">Option</a></code> and <code><a href="../../apidocs/io/vertx/core/cli/Argument.html">Argument</a></code> classes are <em>untyped</em>,
meaning that the only get String values.</p>
</div>
<div class="paragraph">
<p><code><a href="../../apidocs/io/vertx/core/cli/TypedOption.html">TypedOption</a></code> and <code><a href="../../apidocs/io/vertx/core/cli/TypedArgument.html">TypedArgument</a></code> let you specify a <em>type</em>, so the
(String) raw value is converted to the specified type.</p>
</div>
<div class="paragraph">
<p>Instead of
<code><a href="../../apidocs/io/vertx/core/cli/Option.html">Option</a></code> and <code><a href="../../apidocs/io/vertx/core/cli/Argument.html">Argument</a></code>, use <code><a href="../../apidocs/io/vertx/core/cli/TypedOption.html">TypedOption</a></code>
and <code><a href="../../apidocs/io/vertx/core/cli/TypedArgument.html">TypedArgument</a></code> in the <code><a href="../../apidocs/io/vertx/core/cli/CLI.html">CLI</a></code> definition:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create("copy")
    .setSummary("A command line interface to copy files.")
    .addOption(new TypedOption&lt;Boolean&gt;()
        .setType(Boolean.class)
        .setLongName("directory")
        .setShortName("R")
        .setDescription("enables directory support")
        .setFlag(true))
    .addArgument(new TypedArgument&lt;File&gt;()
        .setType(File.class)
        .setIndex(0)
        .setDescription("The source")
        .setArgName("source"))
    .addArgument(new TypedArgument&lt;File&gt;()
        .setType(File.class)
        .setIndex(0)
        .setDescription("The destination")
        .setArgName("target"));</code></pre>
</div>
</div>
<div class="paragraph">
<p>Then you can retrieve the converted values as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CommandLine commandLine = cli.parse(userCommandLineArguments);
boolean flag = commandLine.getOptionValue("R");
File source = commandLine.getArgumentValue("source");
File target = commandLine.getArgumentValue("target");</code></pre>
</div>
</div>
<div class="paragraph">
<p>The vert.x CLI is able to convert to classes:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>having a constructor with a single
<code><a href="../../apidocs/java/lang/String.html">String</a></code> argument, such as <code><a href="../../apidocs/java/io/File.html">File</a></code> or <code><a href="../../apidocs/io/vertx/core/json/JsonObject.html">JsonObject</a></code></p>
</li>
<li>
<p>with a static <code>from</code> or <code>fromString</code> method</p>
</li>
<li>
<p>with a static <code>valueOf</code> method, such as primitive types and enumeration</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>In addition, you can implement your own <code><a href="../../apidocs/io/vertx/core/cli/converters/Converter.html">Converter</a></code> and instruct the CLI to use
this converter:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create("some-name")
    .addOption(new TypedOption&lt;Person&gt;()
        .setType(Person.class)
        .setConverter(new PersonConverter())
        .setLongName("person"));</code></pre>
</div>
</div>
<div class="paragraph">
<p>For booleans, the boolean values are evaluated to <code>true</code>: <code>on</code>, <code>yes</code>, <code>1</code>, <code>true</code>.</p>
</div>
<div class="paragraph">
<p>If one of your option as an <code>enum</code> as type, it computes the set of choices automatically.</p>
</div>
</div>
<div class="sect2">
<h3 id="_using_annotations">Using annotations</h3>
<div class="paragraph">
<p>You can also define your CLI using annotations. Definition is done using annotation on the class and on <em>setter</em>
methods:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">@Name("some-name")
@Summary("some short summary.")
@Description("some long description")
public class AnnotatedCli {

  private boolean flag;
  private String name;
  private String arg;

 @Option(shortName = "f", flag = true)
 public void setFlag(boolean flag) {
   this.flag = flag;
 }

 @Option(longName = "name")
 public void setName(String name) {
   this.name = name;
 }

 @Argument(index = 0)
 public void setArg(String arg) {
  this.arg = arg;
 }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Once annotated, you can define the <code><a href="../../apidocs/io/vertx/core/cli/CLI.html">CLI</a></code> and inject the values using:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">CLI cli = CLI.create(AnnotatedCli.class);
CommandLine commandLine = cli.parse(userCommandLineArguments);
AnnotatedCli instance = new AnnotatedCli();
CLIConfigurator.inject(commandLine, instance);</code></pre>
</div>
</div>
</div>

        

        
          <div id="footer">
            <div id="footer-text">
              
                Last updated 2016-09-12 08:38:04 CEST
              
              
            </div>
          </div>
        
      </div>
    </div>
  </div>
</div>

<footer>
  <div class="container">
    <div class="row">
      <div class="col-xs-6 col-sm-3 col-md-3 col-lg-2">
        <h2>Vert.x</h2>
        <ul class="list-unstyled">
          <li><a href="http://vertx.io/">Home</a></li>
          <li><a href="http://vertx.io/download/">Download</a></li>
          <li><a href="http://vertx.io/docs/">Documentation</a></li>
          <li><a href="https://github.com/vert-x3/wiki/wiki">Wiki</a></li>
          <li><a href="http://vertx.io/blog/">Blog</a></li>
          <li><a href="http://vertx.io/vertx2/" class="vertx-2-link">Vert.x 2</a></li>
        </ul>
      </div>
      <div class="col-xs-6 col-sm-3 col-md-3 col-lg-2">
        <h2>Community</h2>
        <ul class="list-unstyled">
          <li><a href="http://vertx.io/community/">Help &amp; Contributors</a></li>
          <li><a href="http://vertx.io/materials/">Learning materials</a></li>
          <li><a href="https://groups.google.com/forum/?fromgroups#!forum/vertx">User Group</a></li>
          <li><a href="https://groups.google.com/forum/?fromgroups#!forum/vertx-dev">Developer Group</a></li>
        </ul>
      </div>

      <div class="col-xs-12 col-sm-6 col-lg-offset-2 col-md-6 copyright">
        <p>Vert.x is open source and dual licensed under the <a href="https://www.eclipse.org/org/documents/epl-v10.php">Eclipse Public License 1.0</a> and <a href="https://www.apache.org/licenses/LICENSE-2.0.html">Apache License 2.0</a>.</p>
        <p>This website is licensed under the <a href="http://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0 License</a>.<br>
        Design by <a href="http://www.michel-kraemer.com">Michel Kr&auml;mer</a>. <a href="http://www.entypo.com">Entypo pictograms</a> by Daniel Bruce.</p>
        <div class="row">
          <div class="col-xs-12 col-lg-offset-1 col-md-5">
            <a href="http://eclipse.org">
            <img class="logo eclipse-logo" src="http://vertx.io/assets/eclipse_logo_grey_small.png" width="204" height="48">
            </a>
          </div>
          <div class="col-xs-12 col-md-offset-2 col-lg-offset-0 col-md-5">
            <a href="http://cloudbees.com">
            <img class="logo cloudbees-logo" src="http://vertx.io/assets/Button-Built-on-CB-1-grey.png" width="180" height="48">
           </a>
          </div>
          <div class="col-xs-12 col-md-offset-2 col-lg-offset-1 col-md-5 jprofiler">
            <a href="http://www.ej-technologies.com/products/jprofiler/overview.html"
            style="text-decoration:none">
            <img class="logo jprofiler-logo" src="http://vertx.io/assets/jprofiler-logo.png" width="48" height="48"><span class="jprofiler-logo">&nbsp; JPROFILER</span>
            </a>
          </div>
        </div>
      </div>
    </div>
  </div>
</footer>

<script src="http://static.jboss.org/theme/js/libs/jquery/jquery-1.9.1.min.js"></script>
<script src="http://vertx.io/javascripts/bootstrap.min.js"></script>
<script src="http://vertx.io/javascripts/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>



<script src="http://vertx.io/javascripts/sidebar.js"></script>


</body>
</html>
